import { fetchEctranceLists, fetchEctranceDetailInfo, addEctranceDetailInfo } from '../../fetch/modules/ectrance'

const state = {
   ectranceLists: [],
   entranceDetailInfo: {},
   saveDetailInfo: {}
}

const actions = {
    GET_ECTRANCE_LISTS: ({ commit, state }, opts) => {
        return fetchEctranceLists(opts).then(ectrance => commit('FETCH_ENTRANCE_LISTS', { ectrance }))
    },
    FETCH_ENTRANCE_DETAIL: ({ commit, state }, opts) => {
        return fetchEctranceDetailInfo(opts).then(ectrance => commit('FETCH_ENTRANCE_DETAIL_INFO', { ectrance }))
    },
    FETCH_SAVE_ENTRANCE_DETAIL: ({ commit, state }, opts) => {
        return addEctranceDetailInfo(opts).then(ectrance => commit('FETCH_SAVE_ENTRANCE_DETAIL_INFO', { ectrance }))
    },
}
const mutations = {
    FETCH_ENTRANCE_LISTS: (state, { ectrance }) => {
        state.ectranceLists = ectrance.data;
    },
    FETCH_ENTRANCE_DETAIL_INFO: (state, { ectrance }) => {
        state.entranceDetailInfo = ectrance.data;
    },
    FETCH_SAVE_ENTRANCE_DETAIL_INFO: (state, { ectrance }) => {
        state.saveDetailInfo = ectrance.data;
    },
}

const getters = {
    getEctranceLists (state) {
        return state.ectranceLists
    },
    getEctranceDetail (state) {
        return state.entranceDetailInfo
    },
    getSaveEctranceDetailInfo (state) {
        return state.saveDetailInfo
    },
}

export default {
    state,
    actions,
    mutations,
    getters
}